﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Private sv As ScrollView
	Private pmain As Panel
	Private itemname As Label
	Private ivrightarr As ImageView
	Private itemvalue As Label
	Private clvkcinfo As clsCustomListView
	Private pyhq As Panel
	Private kci As kcItem
	Private mi As myInfo
	Private btnkcnumadd As Button
	Private btnkcminus As Button
	Private curyhq As yhq=Null
	Private ksnum As Int=20
	Private dtot As Double
	Private shangmengfangshi,selgrade As String
	Private itemkcnumlbl As Label
	Private lblfudaobanname As Label
	Private lbljiesuankechengprice As Label
	Private lbljiesuanyouhui As Label
	Private lbljiesuanzongjia As Label
	Private pc As PayCls
	Private curPrice As Double
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("laybuy1v1kc")
	initviews
End Sub
Private Sub initviews
	kci=g_store.get("curkc")
	mi=g_store.get("myinfo")
	pc.Initialize(Activity)
	lblfudaobanname.Text=kci.kctitle
	comm.setFA(btnkcminus,"fa-minus","")
	comm.setFA(btnkcnumadd,"fa-plus","")
	comm.setFA(lbljiesuanyouhui,"fa-rmb","0(无优惠)")
	If kci.kctype.EqualsIgnoreCase("1") Then ksnum=1:shangmengfangshi="老师上门"
	curPrice=kci.price_lssm
	calc
	Dim nw As Int=100%x,nh As Int=60dip
	itemkcnumlbl.Text=ksnum
	clvkcinfo.Add(CreateItemCommon("科目年级","请选择年级",nw,nh,True),nh,0)
	clvkcinfo.Add(CreateItemCommon("上课方式","老师上门",nw,nh,True),nh,1)
	clvkcinfo.Add(CreateItemCommon("老师地址",kci.addr,nw,nh,True),nh,2)
	'重建pmain
	pmain.RemoveView
	sv.Panel.AddView(pmain,0,0,pmain.Width,pmain.Height)
	sv.Panel.Height=pmain.Height
End Sub
Private Sub CreateItemCommon(str As String,val As String,w As Int,h As Int,hasArr As Boolean) As Panel
	Dim p As Panel
	p.Initialize("")
	Activity.AddView(p,0,0,w,h)
	p.LoadLayout("itemmodifymyinfocommon")
	ivrightarr.Visible=hasArr
	p.RemoveView
	itemname.Text=str
	itemvalue.Text=val
	Return p
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub clvkcinfo_ItemClick (Index As Int, Value As Object)
	Select Value
		Case 0
			Dim lst As List=g_store.conf.Get(comm.S_NIANJI_FINDTEACHER)
			If lst.IsInitialized=False Then Return
			Dim rid As Int=InputList(lst,"选择所在年级",-1)
			If rid>-1 Then
				comm.setItemVal(clvkcinfo.GetPanel(Value),lst.Get(rid))
				selgrade=lst.Get(rid)
			End If
		Case 1
			Dim lst As List=g_store.conf.Get(comm.S_SKFS)
			If lst.IsInitialized=False Then Return
			Dim ret As Int=InputList(lst,"选择上课方式",-1)
			If ret>-1 Then 
				comm.setItemVal(clvkcinfo.GetPanel(Value),lst.Get(ret))
				shangmengfangshi=lst.Get(ret)
				Select ret
				Case 0
					'xssm
					curPrice=kci.price_xssm
				Case 1
					'lssm
					curPrice=kci.price_lssm
				Case 2
					'xsdz
					curPrice=kci.price_xsdz
				End Select
				calc
			End If
		Case 2
'			Dim amap As clsAMapUri
'			amap.Initialize
'			amap.BiaoZhuSingle("87.546873","43.85675","蜘蛛山")
	End Select
End Sub
Sub yhqselected(yhq As yhq)
	Log(yhq)
	curyhq=yhq
	comm.setItemVal(pyhq,yhq.yhqname&" "&yhq.money)
End Sub
Sub pyhq_Click
	CallSubDelayed2(actYhqList,"selyhq",Me)
'	Dim lst As List
'	lst.Initialize
'	lst.AddAll(Array As String("测试优惠券1","测试优惠券2","测试优惠券3"))
'	Dim ret As Int=InputList(lst,"选择要使用的优惠券",-1)
'	If ret>-1 Then comm.setItemVal(pyhq,lst.Get(ret))
End Sub

Sub ivback_Click
	Activity.Finish
End Sub

Sub btnkcnumadd_Click
	If kci.kctype.EqualsIgnoreCase("1") Then
		Msgbox("试听课限购，不能改变数量","错误")
		Return
	End If
	ksnum=ksnum+1
	itemkcnumlbl.Text=ksnum&""
	calc
End Sub

Sub btnkcminus_Click
	If kci.kctype.EqualsIgnoreCase("1") Then
		Msgbox("试听课限购，不能改变数量","错误")
		Return
	End If
	If ksnum>1 Then
		ksnum=ksnum-1
		calc
	End If
End Sub
Private Sub calc
	itemkcnumlbl.Text=ksnum&""
	comm.setFA(lbljiesuankechengprice,"fa-rmb",$"$1.2{curPrice}"$&"x"&ksnum)
	'lbljiesuankechengprice.Text=kci.price&"x"&ksnum
	If curyhq<>Null And curyhq.IsInitialized Then comm.setFA(lbljiesuanyouhui,"fa-rmb",curyhq.money&"(减免)")
	Try
		dtot=curPrice*ksnum
	Catch
		dtot=0
	End Try
	If curyhq<>Null And curyhq.IsInitialized Then
		If curyhq.uselimit<=dtot Then
			'优惠券满足使用金额
			dtot=dtot-curyhq.money
		Else
			comm.L("不满足优惠券使用条件")
		End If
	End If
	comm.setFA(lbljiesuanzongjia,"fa-rmb",$"$1.2{dtot}"$)
	
End Sub
'Sub JobDone(thj As HttpJob)
'	ProgressDialogHide
'	If thj.Success Then
'		Dim str As String=thj.GetString
'		Dim nr As netRes=ParseHelper.getStatusData(str)
'		comm.L(str)
'		If nr.nCode=200 Then
'			Select thj.JobName
'			Case "subord"
'				comm.TL("订单提交成功")	
'				Dim parser As JSONParser 
'				parser.Initialize(str) 
'				Dim root As Map = parser.NextObject 
'				Dim data As String = root.Get("data") 
'				Dim order_sn As String = root.Get("order_sn") 
'				Dim status As String = root.Get("status") 
'				Dim pi As payItem
'				pi.Initialize
'				pi.title=kci.kctitle
'				pi.money=dtot
'				pi.pid=order_sn
'				g_store.put("pid",pi)
'				StartActivity(actSelectPayMethod)
'				Activity.Finish
'			End Select
'		Else
'			comm.TL("错误:"&nr.sData)
'		End If
'	Else
'		comm.TL("网络错误:"&thj.JobName&thj.ErrorMessage)
'	End If
'	thj.Release
'End Sub
Sub btngopay_Click
	'要提交的参数
	Dim yhqid As String=""
	Dim kcid As String=kci.kcid
	Dim totmoney As String=dtot
	Dim keshi As String=ksnum
	Dim kcmode As String=shangmengfangshi
	Dim addr As String
	If kcmode.Length<1 Then
		comm.TL("请先选择上课方式")
		Return
	End If
	Select kcmode
	Case "学生上门"
		addr=kci.addr
	Case "老师上门"
		addr=mi.address
	Case Else
		addr="待协商"
	End Select
	'检测优惠券是否满足使用条件
	If curyhq<>Null And curyhq.IsInitialized Then
		If curyhq.uselimit<dtot Then
			yhqid=curyhq.yhdid
		Else
			comm.TL("当前订单不满足优惠券使用条件")
			curyhq=Null
		End If	
	End If
	Dim pid As payItem
	pid.Initialize
	pid.title=kci.kctitle
	pid.money=totmoney
	pid.pid=""
	pc.SubmitOrder(kcid,totmoney,keshi,yhqid,kcmode,addr,pid)
End Sub
'Private Sub SubmitOrder(kcid As String,totmoney As String,keshi As String,yhqid As String,kc_mode As String,addr As String)
'	comm.showProgress("正在提交订单请稍后")
'	Dim parms() As String
'	If yhqid.Length>0 Then
'		parms=Array As String("yhj_id",yhqid,"kc_mode",kc_mode,"id",kcid,"money",totmoney,"keshi",keshi,"addr",addr)
'	Else	
'		parms=Array As String("yhj_id","0","kc_mode",kc_mode,"id",kcid,"money",totmoney,"keshi",keshi,"addr",addr)
'	End If
'	ParseHelper.doPostReqArr(Me,"subord",comm.getApi(comm.apiIdx.SUBMITORDER),parms,"")
'	
'End Sub